package com.rw.coco.event;

import com.rw.coco.CocoPlugin;
import com.rw.coco.api.event.PrivateMessageEvent;
import com.rw.coco.api.modle.Account;
import com.rw.coco.api.modle.Bot;
import com.rw.coco.model.KookAccount;
import com.rw.coco.model.KookBot;
import snw.jkook.entity.User;
import snw.jkook.message.PrivateMessage;

public class KookPrivateMessageEvent implements PrivateMessageEvent {
    private final PrivateMessage eventMessage;

    public KookPrivateMessageEvent(PrivateMessage eventMessage) {
        this.eventMessage = eventMessage;
    }

    @Override
    public void delete() {
        eventMessage.delete();
    }

    @Override
    public Bot getBot() {
        User user = CocoPlugin.getInstance().getCore().getUser();
        String name = user.getName();
        String id = user.getId();
        return new KookBot(id, name);
    }

    @Override
    public String getMessage() {
        return eventMessage.getComponent().toString();
    }

    @Override
    public Account getSender() {
        User user = eventMessage.getSender();
        String nickName = user.getName();
        String name = user.getName();
        String id = user.getId();
        return new KookAccount(id, nickName, name);
    }

    @Override
    public void sendBack(String message) {
        eventMessage.reply(message);
    }

    @Override
    public void sendBackSender(String message) {
        eventMessage.sendToSource(message);
    }

    @Override
    public void sendPrivate(String message, String accountId) {
        CocoPlugin.getInstance()
                .getCore()
                .getHttpAPI()
                .getUser(accountId)
                .sendPrivateMessage(message);
    }

    @Override
    public void sendGroup(String message, String groupId) {
        CocoPlugin.getInstance()
                .getCore()
                .getHttpAPI()
                .getTextChannelMessage(groupId)
                .sendToSource(message);
    }
}
